//
// Created by YueChuan on 2023/5/4.
//

#ifndef YUECHUAN_HTTP_SERVER_H
#define YUECHUAN_HTTP_SERVER_H

#include "http_session.h"
#include "tcp_server.h"
#include "servlet.h"

namespace yuechuan {
    namespace http {
        class HttpServer : public TcpServer {
        public:
            typedef std::shared_ptr<HttpServer> ptr;

            /**
             * @brief 含参构造函数
             * @param keepalive 是否长连接
             * @param worker 工作调度器
             * @param io_worker io控制调度器
             * @param accept_worker 接收连接调度器
             */
            HttpServer(bool keepalive = false, IOManager *worker = IOManager::GetThis(),
                       IOManager *io_worker = IOManager::GetThis(), IOManager *accept_worker = IOManager::GetThis());

            /**
             * @brief 获取servlet分发器
             * @return
             */
            ServletDispatch::ptr getServletDispatch() const {return m_dispatch;}

            /**
             * @brief 设置Servlet分发器
             * @param v
             */
            void setServletDispatch(ServletDispatch::ptr v){ m_dispatch = v;}

            /**
             * @brief 设置http服务器名称
             * @param v
             */
            virtual void setName(const std::string& v) override;

        protected:
            /**
             * @brief 处理新链接客户端
             * @param client
             */
            void handleClient(Socket::ptr client) override;

        private:
            bool m_isKeepalive;
            ServletDispatch::ptr m_dispatch;
        };
    }
}


#endif //YUECHUAN_HTTP_SERVER_H
